package ru.lukyanets.transmission.client.action;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.stage.Stage;
import ru.lukyanets.transmission.client.app.PrimaryStage;
import ru.lukyanets.transmission.client.connection.TransmissionService;
import ru.lukyanets.transmission.client.util.DialogUtil;
import ru.lukyanets.transmission.client.util.LocalizationUtil;

/**
 * @author slukyanets
 * @noinspection unused
 */
@Singleton
public class ExitAction extends AbstractAction {
    @Inject
    @PrimaryStage
    private Stage primaryStage;

    @Inject
    private TransmissionService transmissionService;

    @Override
    protected void performAction(ActionEvent event) {
        if(confirmExit()) {
            transmissionService.disconnect();
            Platform.exit();
        }
    }

    private boolean confirmExit() {
        return DialogUtil.showConfirm(primaryStage,
                LocalizationUtil.getString("application.exit.title"),
                LocalizationUtil.getString("application.exit.message"));
    }
}
